package com.globant.google.mendoza;

import java.util.ArrayList;
import java.util.List;

import com.globant.google.mendoza.malbec.BuyerCoupon;
import com.globant.google.mendoza.malbec.BuyerGiftCertificate;
import com.globant.google.mendoza.malbec.BuyerInformation;

/** Holds the mendoza server state. */
public final class MendozaServerState {

  /** The buyer email to log in to checkout.
   */
  private String email;

  /** The password to use to log in to checkout.
   */
  private String password;

  /** The shopping cart.
   */
  private String cart;

  /** The shopping cart signature. */
  private String signature;

  /** The merchant Id.
   */
  private String merchantId;

  /** The merchant key.
   */
  private String merchantKey;

  /** The google order number recieved after posting a cart.
   */
  private String googleOrderNumber;

  /** A list of buyer information.
   */
  private List<BuyerInformation> buyerInformation;

  /** Gets the shopping cart.
   *
   * @return the cart
   */
  public String getShoppingCart() {
    return cart;
  }

  /** Gets the buyer email to log in to checkout.
   *
   * @return the email
   */
  public String getBuyerEmail() {
    return email;
  }

  /** Gets the gogole order number.
   *
   * @return the googleOrderNumber
   */
  public String getGoogleOrderNumber() {
    return googleOrderNumber;
  }

  /** Gets the merchant id.
   *
   * @return the merchantId
   */
  public String getMerchantId() {
    return merchantId;
  }

  /** Gets the merchant key.
   *
   * @return the merchantKey
   */
  public String getMerchantKey() {
    return merchantKey;
  }

  /** Gets the buyer password.
   *
   * @return the password
   */
  public String getBuyerPassword() {
    return password;
  }

  /** Gets the base64 cart signature.
   *
   * @return the signature
   */
  public String getCartSignature() {
    return signature;
  }

  /** Gets the buyer buyer information.
   *
   * @return the buyer buyer information.
   */
  public List<BuyerInformation> getBuyerInformation() {
    return buyerInformation;
  }

  /** Sets the shopping cart.
   *
   * @param theCart the cart to set
   */
  public void setShoppingCart(final String theCart) {
    cart = theCart;
  }

  /** Sets the buyer email.
   *
   * @param theEmail the email to set
   */
  public void setBuyerEmail(final String theEmail) {
    email = theEmail;
  }

  /** Sets the google order number.
   *
   * @param theGoogleOrderNumber the googleOrderNumber to set
   */
  public void setGoogleOrderNumber(final String theGoogleOrderNumber) {
    googleOrderNumber = theGoogleOrderNumber;
  }

  /** Sets the merchant id.
   *
   * @param theMerchantId the merchantId to set
   */
  public void setMerchantId(final String theMerchantId) {
    merchantId = theMerchantId;
  }

  /** Sets the merchant key.
   *
   * @param theMerchantKey the merchantKey to set
   */
  public void setMerchantKey(final String theMerchantKey) {
    merchantKey = theMerchantKey;
  }

  /** Sets the buyer password.
   *
   * @param thePassword the password to set
   */
  public void setBuyerPassword(final String thePassword) {
    password = thePassword;
  }

  /** Sets the cart signature.
   *
   * @param theSignature the signature to set
   */
  public void setCartSignature(final String theSignature) {
    signature = theSignature;
  }

  /** Adds a coupon to the buyer buyerInformation list.
   *
   * @param theCoupon The coupon to add.
   */
  public void addCoupon(final BuyerCoupon theCoupon) {
    if (buyerInformation == null) {
      buyerInformation = new ArrayList<BuyerInformation>();
    }
    buyerInformation.add(theCoupon);
  }

  /** Adds a gift certificate to the buyer buyerInformation list.
   *
   * @param theGiftCertificate The gift certificate to add.
   */
  public void addGiftCertificate(
      final BuyerGiftCertificate theGiftCertificate) {
    if (buyerInformation == null) {
      buyerInformation = new ArrayList<BuyerInformation>();
    }
    buyerInformation.add(theGiftCertificate);
  }

  /** Resets the server state.
   */
  public void reset() {
    email = null;
    password = null;
    cart = null;
    signature = null;
    googleOrderNumber = null;
    buyerInformation = null;
  }
}
